package com.zm.demo.core.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.System.out;

/**
 * Created by Administrator on 2020/1/14.
 */
public class IsPalindrome1 {

    public static boolean isPalindrome(String s) {
        if (s== null){
            return false;
        }
        if (s.length() == 0){
            return true;
        }

        char[] c = s.toLowerCase().toCharArray();

        for (int i = 0, j=c.length-1; i < j; i++,j--) {
            while (!isEffective(c[i]) && i<j){
                i++;
            }
            while (!isEffective(c[j]) && i<j){
                j--;
            }

            if (c[i] != c[j]){
                return false;
            }
        }
        return true;
    }

    private static boolean isEffective(char c){
        return (c >= 'a' && c <= 'z') || (c >='0' && c <= '9');
    }

    private String getStr(String s){
        if (s== null || s.length() == 0){
            return s;
        }
        String regex = "\\w+";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(s);
        StringBuilder sb = new StringBuilder();
        while (matcher.find()){
            sb.append(matcher.group());
        }
        return sb.toString().toLowerCase();
    }
    public static void main(String[]args){
            out.println(isPalindrome("0P"));


    }
}
